﻿bob.ns.setNs('bob.assert', {

    fail: function (sMessage /*, format arguments*/) {

        if (arguments.length <= 1) {
            throw new Error(bob.utils.ifNullOrWhiteSpace(sMessage, 'Assert failed.'));
        }
        else {
            var formatArgs = bob.collections.extensions.clone.call(arguments, 1, arguments.length - 1, [sMessage]);
            var errorMessage = bob.string.formatString.apply(null, formatArgs);
            throw new Error(errorMessage);
        }
    },

    equals: function (expected, actual, sMessage) {

        if (!bob.utils.equals(expected, actual)) {
            bob.assert.fail(bob.utils.ifUndefinedOrNull(sMessage, 'Assert equals failed. Actual: {0}. Expected: {1}.'), actual, expected);
        }

    },

    notEquals: function (comparison, actual, sMessage) {

        if (bob.utils.equals(comparison, actual)) {
            bob.assert.fail(bob.utils.ifUndefinedOrNull(sMessage, 'Assert not-equals failed. Actual: {0}. Comparison: {1}.'), actual, comparison);
        }

    },

    isTrue: function (actual, sMessage) {
        return bob.assert.equals(true, actual, bob.utils.ifUndefinedOrNull(sMessage, 'Assert is-true failed. Actual: {0}.'));
    },

    isFalse: function (actual, sMessage) {
        return bob.assert.equals(false, actual, bob.utils.ifUndefinedOrNull(sMessage, 'Assert is-false failed. Actual: {0}.'));
    },

    throwsError: function (fnTest, sMessage) {
        if (!bob.utils.isFunction(fnTest)) {
            throw new Error('Wrong argument: fnTest.');
        }

        bException = false;
        try {
            fnTest();
        }
        catch (error) {
            bException = true;
        }

        if (!bException) {
            bob.assert.fail(bob.utils.ifUndefinedOrNull(sMessage, 'Assert throws-error failed.'));
        }
    },

    isUndefined: function (actual, sMessage) {
        return bob.assert.isTrue(bob.utils.isUndefined(actual), bob.string.formatString(bob.utils.ifUndefinedOrNull(sMessage, 'Assert is-undefined failed. Actual: {0}.'), actual));
    },

    //v.2
    isNotUndefined: function (actual, sMessage) {
        return bob.assert.isFalse(bob.utils.isUndefined(actual), bob.string.formatString(bob.utils.ifUndefinedOrNull(sMessage, 'Assert is-undefined failed. Actual: {0}.'), actual));
    },

    isNull: function (actual, sMessage) {
        return bob.assert.isTrue(bob.utils.isNull(actual), bob.string.formatString(bob.utils.ifUndefinedOrNull(sMessage, 'Assert is-null failed. Actual: {0}.'), actual));
    },

    //v.2
    isNotNull: function (actual, sMessage) {
        return bob.assert.isFalse(bob.utils.isNull(actual), bob.string.formatString(bob.utils.ifUndefinedOrNull(sMessage, 'Assert is-not-null failed. Actual: {0}.'), actual));
    },

    isUndefinedOrNull: function (actual, sMessage) {
        return bob.assert.isTrue(bob.utils.isUndefinedOrNull(actual), bob.string.formatString(bob.utils.ifUndefinedOrNull(sMessage, 'Assert is-undefined-or-null failed. Actual: {0}.'), actual));
    },

    //v.2
    isNotUndefinedOrNull: function (actual, sMessage) {
        return bob.assert.isFalse(bob.utils.isUndefinedOrNull(actual), bob.string.formatString(bob.utils.ifUndefinedOrNull(sMessage, 'Assert is-not-undefined-or-null failed. Actual: {0}.'), actual));
    },

    //v.2
    isNullOrWhiteSpace: function (actual, sMessage) {
        return bob.assert.isTrue(bob.utils.isNullOrWhiteSpace(actual, true), bob.string.formatString(bob.utils.ifUndefinedOrNull(sMessage, 'Assert is-null-or-whitespace failed. Actual: {0}.'), actual));
    },

    //v.2
    isNotNullOrWhiteSpace: function (actual, sMessage) {
        return bob.assert.isFalse(bob.utils.isNullOrWhiteSpace(actual, true), bob.string.formatString(bob.utils.ifUndefinedOrNull(sMessage, 'Assert is-not-null-or-whitespace failed. Actual: {0}.'), actual));
    },

    //v.2
    isNumber: function (actual, sMessage) {
        return bob.assert.isTrue(bob.utils.isNumber(actual), bob.string.formatString(bob.utils.ifUndefinedOrNull(sMessage, 'Assert is-number failed. Actual: {0}.'), actual));
    },

    //v.2
    isNotNumber: function (actual, sMessage) {
        return bob.assert.isFalse(bob.utils.isNumber(actual), bob.string.formatString(bob.utils.ifUndefinedOrNull(sMessage, 'Assert is-not-number failed. Actual: {0}.'), actual));
    },

    //v.2
    isBoolean: function (actual, sMessage) {
        return bob.assert.isTrue(bob.utils.isBoolean(actual), bob.string.formatString(bob.utils.ifUndefinedOrNull(sMessage, 'Assert is-boolean failed. Actual: {0}.'), actual));
    },

    //v.2
    isNotBoolean: function (actual, sMessage) {
        return bob.assert.isFalse(bob.utils.isBoolean(actual), bob.string.formatString(bob.utils.ifUndefinedOrNull(sMessage, 'Assert is-not-boolean failed. Actual: {0}.'), actual));
    },

    //v.2
    isString: function (actual, sMessage) {
        return bob.assert.isTrue(bob.utils.isString(actual), bob.string.formatString(bob.utils.ifUndefinedOrNull(sMessage, 'Assert is-string failed. Actual: {0}.'), actual));
    },

    //v.2
    isNotString: function (actual, sMessage) {
        return bob.assert.isFalse(bob.utils.isString(actual), bob.string.formatString(bob.utils.ifUndefinedOrNull(sMessage, 'Assert is-not-string failed. Actual: {0}.'), actual));
    },

    //v.2
    isDate: function (actual, sMessage) {
        return bob.assert.isTrue(bob.utils.isDate(actual), bob.string.formatString(bob.utils.ifUndefinedOrNull(sMessage, 'Assert is-date failed. Actual: {0}.'), actual));
    },

    //v.2
    isNotDate: function (actual, sMessage) {
        return bob.assert.isFalse(bob.utils.isDate(actual), bob.string.formatString(bob.utils.ifUndefinedOrNull(sMessage, 'Assert is-not-date failed. Actual: {0}.'), actual));
    },

    //v.2
    isFunction: function (actual, sMessage) {
        return bob.assert.isTrue(bob.utils.isFunction(actual), bob.string.formatString(bob.utils.ifUndefinedOrNull(sMessage, 'Assert is-function failed. Actual: {0}.'), actual));
    },

    //v.2
    isNotFunction: function (actual, sMessage) {
        return bob.assert.isFalse(bob.utils.isFunction(actual), bob.string.formatString(bob.utils.ifUndefinedOrNull(sMessage, 'Assert is-not-function failed. Actual: {0}.'), actual));
    },

    //v.2
    isArray: function (actual, sMessage) {
        return bob.assert.isTrue(bob.utils.isArray(actual), bob.string.formatString(bob.utils.ifUndefinedOrNull(sMessage, 'Assert is-array failed. Actual: {0}.'), actual));
    },

    //v.2
    isNotArray: function (actual, sMessage) {
        return bob.assert.isFalse(bob.utils.isArray(actual), bob.string.formatString(bob.utils.ifUndefinedOrNull(sMessage, 'Assert is-not-array failed. Actual: {0}.'), actual));
    },

    //v.2
    isObject: function (actual, sMessage) {
        return bob.assert.isTrue(bob.utils.isObject(actual), bob.string.formatString(bob.utils.ifUndefinedOrNull(sMessage, 'Assert is-object failed. Actual: {0}.'), actual));
    },

    //v.2
    isNotObject: function (actual, sMessage) {
        return bob.assert.isFalse(bob.utils.isObject(actual), bob.string.formatString(bob.utils.ifUndefinedOrNull(sMessage, 'Assert is-not-object failed. Actual: {0}.'), actual));
    }

});
